import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

var routes = []
const routesM = [
  {
    path: '/',
    redirect: '/login',
  },
  {
    path: '/login',
    name: 'login',
    component: () => import(/* webpackChunkName: "mobile" */ '../views/mobile/login.vue')
  },
  {
    path: '/index',
    name: 'index',
    component: () => import(/* webpackChunkName: "mobile" */ '../views/mobile/index.vue')
  },
  {
    path: '/geren',
    name: 'geren',
    component: () => import(/* webpackChunkName: "mobile" */ '../views/mobile/geren.vue')
  },
  {
    path: '/advertising',
    name: 'advertising',
    component: () => import(/* webpackChunkName: "mobile" */ '../views/mobile/advertising.vue')
  },
]
const routesP = [
  {
    path: '/',
    redirect: '/Auditing'
  },
  {
    path: '/login',
    name: 'login',
    component: () => import(/* webpackChunkName: "pc" */ '../views/pc/login.vue')
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    children: [
      {
        path: '/userList',
        name: 'userList',
        component: () => import(/* webpackChunkName: "pc" */ '../views/pc/userList.vue')
      },
      {
        path: '/Auditing',
        name: 'Auditing',
        component: () => import(/* webpackChunkName: "pc" */ '../views/pc/Auditing.vue')
      },
      {
        path: '/saleUser',
        name: 'saleUser',
        component: () => import(/* webpackChunkName: "pc" */ '../views/pc/saleUser.vue')
      },
      {
        path: '/advertisList',
        name: 'advertisList',
        component: () => import(/* webpackChunkName: "pc" */ '../views/pc/advertisList.vue')
      },
      {
        path: '/seeting',
        name: 'seeting',
        component: () => import(/* webpackChunkName: "pc" */ '../views/pc/seeting.vue')
      },
      {
        path: '/commissionList',
        name: 'commissionList',
        component: () => import(/* webpackChunkName: "pc" */ '../views/pc/commissionList.vue')
      },
      {
        path: '/checkList',
        name: 'checkList',
        component: () => import(/* webpackChunkName: "pc" */ '../views/pc/checkList.vue')
      },
      {
        path: '/commissionData',
        name: 'commissionData',
        component: () => import(/* webpackChunkName: "pc" */ '../views/pc/commissionData.vue')
      },
      // {
      //   path: '/shopData',
      //   name: 'shopData',
      //   component: () => import(/* webpackChunkName: "pc" */ '../views/pc/shopData.vue')
      // },
    ]
  },
  {
    path: '/shopData',
    name: 'shopData',
    component: () => import(/* webpackChunkName: "pc" */ '../views/pc/shopData.vue')
  },
  {
    path: '/meetIngPage',
    name: 'meetIngPage',
    component: () => import(/* webpackChunkName: "pc" */ '../views/pc/meetIngPage.vue')
  },
]


if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
  console.log(1);
  routes = routesM
} else {
  console.log(2);
  routes = routesP
}




const router = new VueRouter({
  routes,
})

router.beforeEach((to, from, next) => {
  if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {

    return next()
  } else {
    // if (to.path === '/login') return next()
    // const userName = window.sessionStorage.userName
    // if (!userName) return next('/login')
    return next()
  }
})




export default router
